{template '_header'}
<script type="text/javascript" src="../addons/mx_shop/static/js/dist/area/cascade.js"></script>
<style>
    .checkbox-inline{
        display: block;
    }    .btns a i{
        display: inline-block;
        width: 100%;
        height: 20px;
        background: #f95959;
    }
    .btn-color {
        width: 25px;
        height: 25px;
        border: 1px solid #fff;
        margin: 2px;
        padding: 0;
    }

</style>
<div class="page-header">
    当前位置：<span class="text-primary">{if !empty($item['id'])}编辑{else}添加{/if}门店
        <small>{if !empty($item['id'])}修改【{$item['storename']}】{/if}</small>
    </span>
</div>

<div class="page-content">
    {ifp 'store.add'}
    <div class="page-sub-toolbar">
        <a class="btn btn-primary btn-sm" href="{php echo webUrl('store/add')}">添加新门店</a>
    </div>
    {/if}
<form {ife 'store' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$item['id']}"/>

    <div class="form-group">
        <label class="col-lg control-label must">门店名称</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <input type="text" name="storename" class="form-control" value="{$item['storename']}"
                   data-rule-required="true"/>
            {else}
            <div class='form-control-static'>{$item['storename']}</div>
            {/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">门店LOGO</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
                {php echo tpl_form_field_image2('logo',$item['logo'])}
            {else}
                {if !empty($item['logo'])}
                <a href='{php echo tomedia($item[' logo'])}' target='_blank'>
                <img src="{php echo tomedia($item['logo'])}" style='width:100px;border:1px solid #ccc;padding:1px' onerror="this.src='../addons/mx_shop/static/images/nopic.png'"/>
                </a>
                {/if}
            {/if}
        </div>
    </div>



    <div class="form-group">
        <label class="col-lg control-label">省市区 :</label>
        <div class="col-sm-9 col-xs-12">
            <p>
                <select id="sel-provance" name="province" onChange="selectCity();" class="select form-control select-group" style="width:123px;display:inline;">
                    <option value="" selected="true">省/直辖市</option>
                </select>
                <select id="sel-city" name="city" onChange="selectcounty(0)" class="select form-control select-group" style="width:135px;display:inline;">
                    <option value="" selected="true">请选择</option>
                </select>
                <select id="sel-area" name="area" onChange="selectstreet(0)" class="select form-control select-group" style="width:130px;display:inline;">
                    <option value="" selected="true">请选择</option>
                </select>

                {if !empty($new_area) && !empty($address_street)}
                <select id="sel-street" name="street" class="select form-control select-group" style="width:220px;display:none;margin-top: 10px;">
                    <option value="" selected="true">请选择</option>
                </select>
                {/if}
            </p>

            <input type="hidden" name="chose_province_code" id="chose_province_code" value="{$item['provincecode']}" />
            <input type="hidden" name="chose_city_code" id="chose_city_code" value="{$item['citycode']}" />
            <input type="hidden" name="chose_area_code" id="chose_area_code" value="{$item['areacode']}" />
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg control-label">门店电话</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <input type="text" name="tel" class="form-control" value="{$item['tel']}"/>
            {else}
            <div class='form-control-static'>{$item['tel']}</div>
            {/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">营业时间</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <input type="text" name="saletime" class="form-control" value="{$item['saletime']}"/>
            {else}
            <div class='form-control-static'>{$item['saletime']}</div>
            {/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">门店位置</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
                {php echo tpl_form_field_position('map',array('lng'=>$item['lng'],'lat'=>$item['lat']))}
            {else}
                <div class='form-control-static'>lng={$item['lng']},lat={$item['lat']}</div>
            {/if}
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg control-label">门店地址</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <input type="text" name="address" class="form-control" value="{$item['address']}"/>
            {else}
            <div class='form-control-static'>{$item['address']}</div>
            {/if}
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg control-label">门店支持</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
                <label class='radio-inline'>
                    <input type='radio' name='type' value='1' {if $item['type']==1}checked{/if} /> 支持自提
                </label>

                <label class='radio-inline'>
                    <input type='radio' name='type' value='2' {if $item['type']==2}checked{/if} /> 支持核销
                </label>

                <label class='radio-inline'>
                    <input type='radio' name='type' value='3' {if $item['type']==3}checked{/if} /> 支持自提+核销
                </label>

                <label class='radio-inline'>
                    <input type='radio' name='type' value='0' {if $item['type']==0}checked{/if} /> 全都不支持
                </label>
            {else}
                <div class='form-control-static'>{if $item['type']==0}全都不支持{else if $item['type']==1}支持自提{else if $item['type']==2}支持核销{else if
                    $item['type']==3}支持自提+核销{/if}
                </div>
            {/if}
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg control-label">联系人信息</label>
        <div class="col-sm-10 col-xs-12">
            {ife 'store' $item}
                <label class="radio-inline" style="float: left;padding-left:0px;">姓名</label>
                <div class="col-sm-9 col-xs-12" style="width: 120px; float: left; margin: 0px 20px 0px -5px;">
                    <input type="text" value="{$item['realname']}" class="form-control" name="realname"
                           style="width:120px;padding:5px;">
                </div>
                <label class="radio-inline" style="float: left;">电话</label>
                <div class="col-sm-9 col-xs-12" style="width: 120px; float: left; margin: 0px 20px 0px -5px;">
                    <input type="text" value="{$item['mobile']}" class="form-control" name="mobile"
                           style="width:120px;padding:5px;">
                </div>
            {else}
                <div class='form-control-static'>联系人:{$item['realname']} 联系电话:{$item['mobile']}</div>
            {/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">门店简介</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <textarea name="desc" class="form-control richtext" rows="5">{$item['desc']}</textarea>
            {else}
            <div class='form-control-static'>{$item['desc']}</div>
            {/if}
        </div>
    </div>

{if p('newstore')}
    <div class="form-group">
        <label class="col-lg control-label">门店标签</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}

                <div class='label-items'>
                    {loop $label $ite}
                        <div class="input-group recharge-item" style="width:300px;margin-top:5px">
                            <span class="input-group-addon">内容</span>
                            <input type="text" class="form-control" name='lab[]' maxlength="20"  style="width:200px;" value="{$ite}" />
                            <div class='input-group-btn'>
                                <button class='btn btn-danger' type='button' onclick="removeLabelItem(this)"><i class='fa fa-remove'></i></button>
                            </div>
                        </div>
                    {/loop}
                </div>


                <div style="margin-top:5px">
                    <button type='button' class="btn btn-default" onclick='addLabelItem()' style="margin-bottom:5px"><i class='fa fa-plus'></i> 增加标签项</button>
                </div>
                <span class="help-block">显示在店铺详情和列表页的标识文字, 最多添加8个,每个标签长度不能超过20个字符</span>

            {else}
                <div class='label-items'>
                    {loop $label $ite}
                    <div class="input-group recharge-item" style="width:300px;margin-top:5px">
                        <span class="input-group-addon">内容</span>
                        <div class='form-control-static'></div>
                    </div>
                    {/loop}
                </div>
            {/if}
        </div>
    </div>


    <div class="form-group">
        <label class="col-lg control-label">门店角标</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}

            <div class='tag-items'>
                {loop $tag $ite}
                <div class="input-group recharge-item" style="width:300px;margin-top:5px">
                    <span class="input-group-addon">内容</span>
                    <input type="text" class="form-control" name='tag[]' maxlength="20"  style="width:200px;" value="{$ite}" />
                    <div class='input-group-btn'>
                        <button class='btn btn-danger' type='button' onclick="removeTagItem(this)"><i class='fa fa-remove'></i></button>
                    </div>
                </div>
                {/loop}
            </div>


            <div style="margin-top:5px">
                <button type='button' class="btn btn-default" onclick='addTagItem()' style="margin-bottom:5px"><i class='fa fa-plus'></i> 增加角标项</button>
            </div>
            <span class="help-block">显示在店铺详情和列表页的标识文字, 最多添加3个,每个角标长度不能超过3个字符</span>

            {else}
            <div class='label-items'>
                {loop $tag $ite}
                <div class="input-group recharge-item" style="width:300px;margin-top:5px">
                    <span class="input-group-addon">内容</span>
                    <div class='form-control-static'></div>
                </div>
                {/loop}
            </div>
            {/if}
        </div>
    </div>

    {loop $data $list2}
    {template ''}
    {/loop}

    <div class="form-group">
        <label class="col-lg control-label">轮播图</label>
        <div class="col-sm-9 col-xs-12">
            {php echo tpl_form_field_multi_image2('banner',$item['banner'])}
        </div>
    </div>

    {if p('newstore')}
    <div class="form-group">
        <label class="col-lg control-label">门店分类</label>
        <div class="col-sm-8 col-xs-12">
            {ife 'category' $item}
            <select id="cates"  name='cates[]' class="form-control select2" style='width:605px;' multiple='' >
                {loop $category $c}
                <option value="{$c['id']}" {if is_array($cates) &&  in_array($c['id'],$cates)}selected{/if} >{$c['name']}</option>
                {/loop}
            </select>
            {else}
            <div class='form-control-static ops'>
                {loop $cates $c}
                <a>{$category[$c]['name']}</a>
                {/loop}
            </div>

            {/if}
        </div>
    </div>

    <!--<div class="form-group">-->
        <!--<label class="col-lg control-label">门店分组</label>-->
        <!--<div class="col-sm-9 col-xs-12">-->
            <!--<select name="storegroupid" id="" class="form-control">-->
                <!--<option>请选择</option>-->
                <!--{loop $storegroup $k $v}-->
                <!--<option value="{$v['id']}" {if $v['id']==$item['storegroupid']}selected="true"{/if} >{$v['name']}</option>-->
                <!--{/loop}-->
            <!--</select>-->
        <!--</div>-->
    <!--</div>-->
    {/if}

    <div class="form-group">
        <label class="col-lg control-label must">权限管理</label>
        <div class="col-sm-9 col-xs-12">
            <div class="col-sm-10">
                <label class="checkbox-inline" >
                    <input type="checkbox" name="perms[]" value="storeinfo" {if in_array('storeinfo',$perms)} checked{/if}>  门店基本信息编辑</label>
                <label class="checkbox-inline"  >
                    <input type="checkbox" name="perms[]" value="saler" {if in_array('saler',$perms)} checked{/if}>  店员管理</label>
           <!--     <label class="checkbox-inline">
                    <input type="checkbox" name="perms[]" value="sale" {if in_array('sale',$perms)} checked{/if}>  营销管理</label>-->
                <label class="checkbox-inline">
                    <input type="checkbox" name="perms[]" value="stock"  {if in_array('stock',$perms)} checked{/if}>  商品库存管理</label>
                <label class="checkbox-inline">
                    <input type="checkbox" name="perms[]" value="delete" {if in_array('delete',$perms)} checked{/if} >  商品上架下架</label>
                <label class="checkbox-inline">
                    <input type="checkbox" name="perms[]" value="norder" {if in_array('norder',$perms)} checked{/if}>  预约商品管理</label>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg control-label">门店发货</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <label class='radio-inline'>
                <input type='radio' name='opensend' value=1' {if $item['opensend']==1}checked{/if} /> 允许
            </label>
            <label class='radio-inline'>
                <input type='radio' name='opensend' value=0' {if $item['opensend']==0}checked{/if} /> 禁止
            </label>
            {else}
            <div class='form-control-static'>{if $item['opensend']==1}允许{else}禁止{/if}</div>
            {/if}
        </div>
    </div>
{/if}


    <div class="form-group">
        <label class="col-lg control-label">状态</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <label class='radio-inline'>
                <input type='radio' name='status' value=1' {if $item['status']==1}checked{/if} /> 启用
            </label>
            <label class='radio-inline'>
                <input type='radio' name='status' value=0' {if $item['status']==0}checked{/if} /> 禁用
            </label>
            {else}
            <div class='form-control-static'>{if $item['status']==1}启用{else}禁用{/if}</div>
            {/if}
        </div>
    </div>

    {if $printer}
    <div class="form-group">
        <label class="col-lg control-label">选择订单打印机</label>
        <div class="col-sm-9 col-xs-12">
            {ifp 'sysset.printer.set'}
            <?php echo tpl_selector('order_printer',array(
             'preview'=>true,
            'readonly'=>true,
            'nokeywords'=>true,
            'multi'=>1,
            'value'=>$item['title'],
            'url'=>webUrl('sysset/printer/printer_query'),
            'items'=>$order_printer_array,
            'buttontext'=>'选择订单打印机',
            'placeholder'=>'请选择订单打印机')
            )?>
            {else}
            <div class="input-group multi-img-details container ui-sortable">
                {loop $order_printer_array $it}
                <div data-name="goodsid" data-id="{$it['id']}" class="multi-item">
                    <img src="{php echo tomedia($it['thumb'])}" class="img-responsive img-thumbnail">
                    <div class="img-nickname">{$it['title']}</div>
                </div>
                {/loop}
            </div>

            {/if}
        </div>
    </div>

    <div class="form-group">
        <label class="col-lg control-label">选择订单打印模板</label>
        <div class="col-sm-9 col-xs-12">
            {ifp 'sysset.printer.set'}
            <select class='form-control' name='order_template'>
                <option>选择您需要的订单打印模板</option>
                {loop $order_template $value}
                <option value="{$value['id']}" {if $value['id']==$item['order_template']}selected{/if}>{$value['title']}</option>
                {/loop}
            </select>
            {else}
            <div class='form-control-static'>
                {if empty($item['order_template'])}选择您需要的订单打印模板{else}{$item['order_template']}{/if}
            </div>
            {/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg control-label">订单打印方式</label>
        <div class="col-sm-9 col-xs-12">
            {ifp 'sysset.notice.edit'}
            <label class="checkbox-inline">
                <input type="checkbox" value="1" name='ordertype[]' {if in_array('1',$ordertype)}checked{/if} /> 下单打印
            </label>
            <label class="checkbox-inline">
                <input type="checkbox" value="2" name='ordertype[]' {if in_array('2',$ordertype)}checked{/if} /> 付款打印
            </label>
            <label class="checkbox-inline">
                <input type="checkbox" value="3" name='ordertype[]' {if in_array('3',$ordertype)}checked{/if} /> 确认收货打印
            </label>
            <div class="help-block">通知商家方式</div>
            {else}
            <input type="hidden" name="data[ordertype]" value="{$data['ordertype']}"/>
                <div class='form-control-static'>{if in_array('1',$ordertype)}下单打印;{/if}
                    {if  in_array('2',$ordertype)}付款打印;{/if}{if in_array('3',$ordertype)}确认收货打印;{/if}
                </div>
            {/if}
        </div>
    </div>
    {/if}


    <div class="form-group"></div>
    <div class="form-group">
        <label class="col-lg control-label"></label>
        <div class="col-sm-9 col-xs-12">
            {ife 'store' $item}
            <input type="submit" value="提交" class="btn btn-primary"/>

            {/if}
            <input type="button" name="back" onclick='history.back()' {ifp  'store.add|store.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
        </div>
    </div>
</form>
</div>
<script language='javascript'>
    $(function () {
        $(':radio[name=type]').click(function () {
            type = $("input[name='type']:checked").val();

            if (type == '1' || type == '3') {
                $('#pick_info').show();
            } else {
                $('#pick_info').hide();
            }
        })
    })

    //添加标签
    function addLabelItem(){
        if($('.label-items')[0].childElementCount<8)
        {
            var html= '<div class="input-group recharge-item"  style="width:300px;margin-top:5px">';
            html+='<span class="input-group-addon">内容</span>';
            html+='<input type="text" class="form-control"  style="width:200px;" maxlength="20" name="lab[]"  />';
            html+='<div class="input-group-btn"><button class="btn btn-danger" type="button" onclick="removeLabelItem(this)"><i class="fa fa-remove"></i></button></div></div>';

            $('.label-items').append(html);
        }else{
            tip.msgbox.err("标签最多八个!");
        }
    }

    //添加角标
    function addTagItem(){
        if($('.tag-items')[0].childElementCount<3)
        {
            var html= '<div class="input-group recharge-item"  style="width:300px;margin-top:5px">';
            html+='<span class="input-group-addon">内容</span>';
            html+='<input type="text" class="form-control"  style="width:200px;" maxlength="3" name="tag[]"  />';
            html+='<div class="input-group-btn"><button class="btn btn-danger" type="button" onclick="removeTagItem(this)"><i class="fa fa-remove"></i></button></div></div>';

            $('.tag-items').append(html);
        }else{
            tip.msgbox.err("角标最多三个!");
        }
    }

    //删除标签
    function removeLabelItem(obj){
        $(obj).closest('.recharge-item').remove();
    }
    //删除角标
    function removeTagItem(obj){
        $(obj).closest('.recharge-item').remove();
    }

    cascdeInit("{php echo $new_area}","{php echo $address_street}","{php echo isset($item['province'])?$item['province']:''}","{php echo isset($item['city'])?$item['city']:''}","{php echo isset($item['area'])?$item['area']:''}","''");
</script>
{template '_footer'}